package com.ff.discounts.component.shop

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.ff.discounts.R
import com.ff.discounts.component.productdetail.ProductDetailActivity
import com.ff.discounts.component.tab.home.HistoryData
import com.ff.discounts.databinding.FragmentShopBinding
import com.ff.discounts.fragment.BaseViewModelFragment
import com.ff.discounts.util.Constant

/**
 * 商品内容界面
 * @author: fufang
 * @date: 2023/10/26
 */
class ShopFragment : BaseViewModelFragment<FragmentShopBinding>() {
    private lateinit var adapter: ShopGoodsAdapter

    override fun initViews() {
        super.initViews()
        // 适配器布局
        binding.list.apply {
            layoutManager = LinearLayoutManager(hostActivity)
        }


    }

    override fun initListeners() {
        super.initListeners()
        adapter.setOnItemClickListener{
            adapter,view,position ->
               startActivity(ProductDetailActivity::class.java)
        }
    }

    override fun initDatum() {
        super.initDatum()
        // 适配器
        adapter = ShopGoodsAdapter()
        binding.list.adapter = adapter
        adapter.submitList(historyDataList)
    }

    companion object{
        fun newInstance(
            categoryId:String? = null,
            index:Int = Constant.VALUE_NO

        ):ShopFragment{
            val args = Bundle()
            args.putInt(Constant.INDEX,index)
            categoryId.let {
                args.putString(Constant.ID,it)
            }
            val fragment = ShopFragment()
            fragment.arguments = args
            return  fragment
        }

        private val historyDataList = mutableListOf<HistoryData>(
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集")

        )
    }
}